import datetime
import random

from flask import  current_app
from flask_script import Manager
from flask_migrate import MigrateCommand

from info import create_app
# 调整模式参数dev或者pro


app = create_app("dev")
# 创建管理者对象
mar = Manager(app)

mar.add_command("mc",MigrateCommand)


# 创建管理员
@mar.option("-name","-n",dest="name")
@mar.option("-password","-p",dest="password")
def create_supermanage(name,password):
    from info.models import User
    from info import db
    if not all([name,password]):
        print("参数不足")
        return

    # 创建用户模型
    user = User()

    user.mobile = name
    user.password = password
    user.nick_name = name
    user.is_admin = True


    try:
        db.session.add(user)
        db.session.commit()
    except BaseException as e:
        current_app.logger.error(e)

    print("管理员创建成功")



if __name__ == '__main__':
    mar.run()

